package com.nbcio.modules.erp.cart.controller;

import com.nbcio.modules.erp.cart.service.CartService;
import com.nbcio.modules.erp.cart.service.ISysUserServiceNew;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author
 * @ClassName CartController
 * @Description 购物车接口
 * @date 2024/4/10 15:36
 * @Version 1.0
 */
@Api(tags="购物车")
@RequestMapping("/sys/cart")
@RestController
@Slf4j
public class CartController {

    @Autowired
    private CartService cartService;

    @Autowired
    private ISysUserServiceNew sysUserService;

    @AutoLog(value = "购物车-添加")
    @ApiOperation(value="购物车-添加", notes="购物车-添加")
    @PostMapping("/add")
    public Result<?> add(@RequestBody Map<String,Object> map){
        cartService.saveMain(map);
        return Result.OK("购物车添加成功");
    }

    @AutoLog(value = "购物车-修改")
    @ApiOperation(value="购物车-修改", notes="购物车-修改")
    @PostMapping("/edit")
    public Result<?> edit(@RequestBody Map<String,Object> map){
        cartService.updateMain(map);
        return Result.OK("购物车修改成功");
    }

    @AutoLog(value = "购物车-删除")
    @ApiOperation(value="购物车-删除", notes="购物车-删除")
    @PostMapping("/delete")
    public Result<?> delete(@RequestBody Map<String,Object> map){
        cartService.deleteMain(map);
        return Result.OK("购物车删除成功");
    }

    @AutoLog(value = "购物车-批量删除")
    @ApiOperation(value="购物车-批量删除", notes="购物车-批量删除")
    @PostMapping("/batchDelete")
    public Result<?> batchDelete(@RequestBody Map<String,Object> map){
        cartService.deleteBatchMain(map);
        return Result.OK("购物车批量删除成功");
    }

    @AutoLog(value = "购物车-查询")
    @ApiOperation(value="购物车-查询", notes="购物车-查询")
    @PostMapping("/query")
    public Result<?> query(@RequestBody Map<String,Object> map){
        Map<String,Object> result = cartService.queryMain(map.get("id").toString());
        return Result.OK(result);
    }


    @AutoLog(value = "用户-修改密码")
    @ApiOperation(value="用户-修改密码", notes="用户-修改密码")
    @PostMapping("/modifyPassword")
    public Result<?> modifyPassword(@RequestBody Map<String,Object> map){
        sysUserService.modifyPassword(map);
        return Result.OK("修改密码成功");
    }

    @AutoLog(value = "用户-修改头像")
    @ApiOperation(value="用户-修改头像", notes="用户-修改头像")
    @PostMapping("/modifyImg")
    public Result<?> modifyImg(@RequestPart("file") MultipartFile file, @RequestParam("user_id") String user_id){
        sysUserService.modifyImg(file,user_id);
        return Result.OK("修改头像成功");
    }
}
